package com.hethongviet.job;

import java.util.List;
import java.util.Vector;

import com.hethongviet.job.models.Project;
import com.hethongviet.job.models.Task;
import com.hethongviet.job.models.User;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class AppMain extends Application
{
	public static final int ACTIVATION_CODE_CHAR_LENGTH = 8;

	public static final int ERROR_CODE_WRONG_USERNAME_OR_PASSWORD = 0;
	public static final int ERROR_CODE_WRONG_ACTIVATION_CODE = 1;
	public static final int ERROR_CODE_ACTIVATION_CODE_OUT_OF_DATE = 2;
	public static final int ERROR_CODE_ACTIVATION_CODE_USED_BY_OTHER = 3;
	
	public static List<Project> _projectsList = new Vector<Project>(); 
	public static List<Task> _tasksList = new Vector<Task>();
	
	public static User _user = new User();
	public static Project _currentProject = null;
	public static Task _currentTask = null;

	public static boolean _isDebug = true;
	
	public AppMain()
	{

	}

	public static void makeFullScreen(Activity activity)
	{
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		activity.getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}

	public static boolean isNetworkAvailable(Context context)
	{
		final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		if (networkInfo != null && networkInfo.isAvailable()
				&& networkInfo.isConnected()) return true;
		else return false;
	}

	public static void showMessageBox(Context context, String message)
	{
		Toast.makeText(context, message, Toast.LENGTH_LONG);
	}

	public static void alert(Context context, String title, String message)
	{
		AlertDialog.Builder builder = new Builder(context);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton("Back", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which)
			{
			}
		});
		builder.show();
	}
}
